package servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "Servlet13", value = "/reg")
public class Servlet13 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //乱码大致有两种情况：
        //1.请求乱码（客--->服）
        //      request.setCharacterEncoding("utf-8");
        //2.响应乱码（服--->客）
        //   两种方法：response.setCharacterEncoding("utf-8");
        // (推荐第2种) response.setContentType("text/html;charset=utf-8");


        response.setContentType("text/html;charset=utf-8");
//        getParameter赋单值
        String username = request.getParameter("username");
        String password = request.getParameter("password");
//        getParameterValues赋多值
        String[] hobby = request.getParameterValues("hobby");
        PrintWriter out = response.getWriter();
        out.println(username);
        out.println(password);
       for (String h : hobby){
           out.println(h);
       }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
